package uk.ac.sanger.das.dasregistry.springrest.sources.utils;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

import org.biodas.jdas.dassources.utils.DasTimeFormat;
import org.biodas.jdas.dassources.utils.PropInterogator;
import org.biodas.jdas.schema.sources.PROP;
import org.biodas.jdas.schema.sources.SOURCE;



/**
 * class to code timer functionality for the registry warnings for old leaseDates
 * @author jw12
 *
 */
public class RegistryTimer {
	private static int ARCHIVE_TIME=60;//60 days from invalid to deletion 
	int oneday=1000 * 60 * 60 * 24;
	int twodays = 1000 * 60 * 60 * 24 * 2;
	int warningOfDeletionTime= 1000 * 60 * 60 * 24 * RegistryTimer.ARCHIVE_TIME /2;//to show row as red as immenently going to be deleteds
	
	public boolean isActive(SOURCE ds){
		boolean isActive=true;
	List<PROP> props = ds.getVERSION().get(0).getPROP();
	String days=PropInterogator.getPropByName("daysBeforeDeletion", props);
	if(days!=null){
		isActive=false;
	}
	return isActive;
	}
	
	public int daysInactive(String leaseTime){
	Date now = new Date();
	Date leaseDate=null;
	try {
		leaseDate = DasTimeFormat.fromDASString(leaseTime);
	} catch (ParseException e) {
		//  Auto-generated catch block
		e.printStackTrace();
	}
	long timeSinceLeaseTime=now.getTime()-leaseDate.getTime();
	int daysInactive=(int) (timeSinceLeaseTime/oneday);
	
	return daysInactive;
	}
		
}
